import Enity from "./Enity.js"
import HpProp from "./HpProp.js"
import FireProp from "./FireProp.js"
import { enemy01Body,boo } from "../image.js"
class Enemy01Enity extends Enity {
    type = 'enemy'
    name = "敌人01"
    score = 10 //击杀后玩家所获得的分数
    hp = 2
    img;//敌人的图片
    v;//移动速度
    time = 0;//存活时间
    
    //参数
    timer=null;//内置定时器

    constructor(x, y) {
        super(x, y, 20)
        this.img = {
            body:enemy01Body,
            boo
        }
        this.v = 2
    }
    draw(ctx) {
        if(this.hp>0){
            ctx.drawImage(this.img.body, this.x - this.R, this.y - this.R, this.R * 2, this.R * 2)
        }else{
            ctx.drawImage(this.img.boo[this.time%5], this.x - this.R, this.y - this.R, this.R * 2, this.R * 2)
        }
    }
    behavior = function(context){
        this.time++
        this.move(context)
        return context
    }
    move(){
        if(this.hp <= 0) return
        this.y+=this.v;
    }
    isOK(context){
        if(this.y>=600){
            this.OK=false
        }
        if(this.hp<=0){
            if(!this.timer){
                if(!context.gameOver) context.score+=this.score
                //概率掉道具
                if(0.1>=Math.random()){
                    context.NodeList.push(new HpProp(this.x,this.y))
                }
                if (0.03 >= Math.random()) {
                    context.NodeList.push(new FireProp(this.x, this.y))
                }
                this.timer = setTimeout(()=>{
                    this.OK = false
                },1000)
            }
        }
        return context
    }
}
export default Enemy01Enity